# encoding: utf-8

# FIXME this is hack stemming from the fact that there's not easy way how to
# search countries by country_code. Once I figure out the more elegant way, I'll
# remove it

module Adapi
  class ConstantData::Location < ConstantData
    class Country

      COUNTRIES = [
        ["Afghanistan","AF","2004"],
        ["Albania","AL","2008"],
        ["Algeria","DZ","2012"],
        ["American Samoa","AS","2016"],
        ["Andorra","AD","2020"],
        ["Angola","AO","2024"],
        ["Anguilla","AI","2660"],
        ["Antarctica","AQ","2010"],
        ["Antigua and Barbuda","AG","2028"],
        ["Argentina","AR","2032"],
        ["Armenia","AM","2051"],
        ["Aruba","AW","2533"],
        ["Australia","AU","2036"],
        ["Austria","AT","2040"],
        ["Azerbaijan","AZ","2031"],
        ["Bahamas","BS","2044"],
        ["Bahrain","BH","2048"],
        ["Bangladesh","BD","2050"],
        ["Barbados","BB","2052"],
        ["Belarus","BY","2112"],
        ["Belgium","BE","2056"],
        ["Belize","BZ","2084"],
        ["Benin","BJ","2204"],
        ["Bermuda","BM","2060"],
        ["Bhutan","BT","2064"],
        ["Bolivia","BO","2068"],
        ["Bosnia and Herzegovina","BA","2070"],
        ["Botswana","BW","2072"],
        ["Bouvet Island","BV","2074"],
        ["Brazil","BR","2076"],
        ["British Indian Ocean Territory","IO","2086"],
        ["Brunei Darussalam","BN","2096"],
        ["Bulgaria","BG","2100"],
        ["Burkina Faso","BF","2854"],
        ["Burundi","BI","2108"],
        ["Cambodia","KH","2116"],
        ["Cameroon","CM","2120"],
        ["Canada","CA","2124"],
        ["Cape Verde","CV","2132"],
        ["Cayman Islands","KY","2136"],
        ["Central African Republic","CF","2140"],
        ["Chad","TD","2148"],
        ["Chile","CL","2152"],
        ["China","CN","2156"],
        ["Christmas Island","CX","2162"],
        ["Cocos (Keeling) Islands","CC","2166"],
        ["Colombia","CO","2170"],
        ["Comoros","KM","2174"],
        ["Congo","CG","2178"],
        ["Congo, Democratic Republic","CD","2180"],
        ["Cook Islands","CK","2184"],
        ["Costa Rica","CR","2188"],
        ["Cote d'Ivoire","CI","2384"],
        ["Croatia","HR","2191"],
        ["Cyprus","CY","2196"],
        ["Czech Republic","CZ","2203"],
        ["Denmark","DK","2208"],
        ["Djibouti","DJ","2262"],
        ["Dominica","DM","2212"],
        ["Dominican Republic","DO","2214"],
        ["East Timor","TL","2626"],
        ["Ecuador","EC","2218"],
        ["Egypt","EG","2818"],
        ["El Salvador","SV","2222"],
        ["Equatorial Guinea","GQ","2226"],
        ["Eritrea","ER","2232"],
        ["Estonia","EE","2233"],
        ["Ethiopia","ET","2231"],
        ["Falkland Islands (Malvinas)","FK","2238"],
        ["Faroe Islands","FO","2234"],
        ["Fiji","FJ","2242"],
        ["Finland","FI","2246"],
        ["France","FR","2250"],
        ["French Guiana","GF","2254"],
        ["French Polynesia","PF","2258"],
        ["French Southern Territories","TF","2260"],
        ["Gabon","GA","2266"],
        ["Gambia","GM","2270"],
        ["Georgia","GE","2268"],
        ["Germany","DE","2276"],
        ["Ghana","GH","2288"],
        ["Gibraltar","GI","2292"],
        ["Greece","GR","2300"],
        ["Greenland","GL","2304"],
        ["Grenada","GD","2308"],
        ["Guadeloupe","GP","2312"],
        ["Guam","GU","2316"],
        ["Guatemala","GT","2320"],
        ["Guinea","GN","2324"],
        ["Guinea-Bissau","GW","2624"],
        ["Guyana","GY","2328"],
        ["Haiti","HT","2332"],
        ["Heard and McDonald Islands","HM","2334"],
        ["Honduras","HN","2340"],
        ["Hong Kong","HK","2344"],
        ["Hungary","HU","2348"],
        ["Iceland","IS","2352"],
        ["India","IN","2356"],
        ["Indonesia","ID","2360"],
        ["Iraq","IQ","2368"],
        ["Ireland","IE","2372"],
        ["Israel","IL","2376"],
        ["Italy","IT","2380"],
        ["Jamaica","JM","2388"],
        ["Japan","JP","2392"],
        ["Jordan","JO","2400"],
        ["Kazakhstan","KZ","2398"],
        ["Kenya","KE","2404"],
        ["Kiribati","KI","2296"],
        ["Kuwait","KW","2414"],
        ["Kyrgyzstan","KG","2417"],
        ["Lao People's Democratic Republic","LA","2418"],
        ["Latvia","LV","2428"],
        ["Lebanon","LB","2422"],
        ["Lesotho","LS","2426"],
        ["Liberia","LR","2430"],
        ["Libya","LY","2434"],
        ["Liechtenstein","LI","2438"],
        ["Lithuania","LT","2440"],
        ["Luxembourg","LU","2442"],
        ["Macau","MO","2446"],
        ["Macedonia","MK","2807"],
        ["Madagascar","MG","2450"],
        ["Malawi","MW","2454"],
        ["Malaysia","MY","2458"],
        ["Maldives","MV","2462"],
        ["Mali","ML","2466"],
        ["Malta","MT","2470"],
        ["Marshall Islands","MH","2584"],
        ["Martinique","MQ","2474"],
        ["Mauritania","MR","2478"],
        ["Mauritius","MU","2480"],
        ["Mayotte","YT","2175"],
        ["Mexico","MX","2484"],
        ["Micronesia","FM","2583"],
        ["Moldova","MD","2498"],
        ["Monaco","MC","2492"],
        ["Mongolia","MN","2496"],
        ["Montserrat","MS","2500"],
        ["Morocco","MA","2504"],
        ["Mozambique","MZ","2508"],
        ["Namibia","NA","2516"],
        ["Nauru","NR","2520"],
        ["Nepal","NP","2524"],
        ["Netherlands","NL","2528"],
        ["Netherlands Antilles","AN","2530"],
        ["New Caledonia","NC","2540"],
        ["New Zealand","NZ","2554"],
        ["Nicaragua","NI","2558"],
        ["Niger","NE","2562"],
        ["Nigeria","NG","2566"],
        ["Niue","NU","2570"],
        ["Norfolk Island","NF","2574"],
        ["Northern Mariana Islands","MP","2580"],
        ["Norway","NO","2578"],
        ["Oman","OM","2512"],
        ["Pakistan","PK","2586"],
        ["Palau","PW","2585"],
        ["Palestinian Territory","PS","2275"],
        ["Panama","PA","2591"],
        ["Papua New Guinea","PG","2598"],
        ["Paraguay","PY","2600"],
        ["Peru","PE","2604"],
        ["Philippines","PH","2608"],
        ["Pitcairn","PN","2612"],
        ["Poland","PL","2616"],
        ["Portugal","PT","2620"],
        ["Puerto Rico","PR","2630"],
        ["Qatar","QA","2634"],
        ["Reunion","RE","2638"],
        ["Romania","RO","2642"],
        ["Russian Federation","RU","2643"],
        ["Rwanda","RW","2646"],
        ["Saint Kitts and Nevis","KN","2659"],
        ["Saint Lucia","LC","2662"],
        ["Saint Vincent and the Grenadines","VC","2670"],
        ["Samoa","WS","2882"],
        ["San Marino","SM","2674"],
        ["Sao Tome and Principe","ST","2678"],
        ["Saudi Arabia","SA","2682"],
        ["Senegal","SN","2686"],
        ["Serbia and Montenegro","CS","2891"],
        ["Seychelles","SC","2690"],
        ["Sierra Leone","SL","2694"],
        ["Singapore","SG","2702"],
        ["Slovakia","SK","2703"],
        ["Slovenia","SI","2705"],
        ["Solomon Islands","SB","2090"],
        ["Somalia","SO","2706"],
        ["South Africa","ZA","2710"],
        ["South Georgia and The South Sandwich Islands","GS","2239"],
        ["South Korea","KR","2410"],
        ["Spain","ES","2724"],
        ["Sri Lanka","LK","2144"],
        ["St. Helena","SH","2654"],
        ["St. Pierre and Miquelon","PM","2666"],
        ["Suriname","SR","2740"],
        ["Svalbard and Jan Mayen Islands","SJ","2744"],
        ["Swaziland","SZ","2748"],
        ["Sweden","SE","2752"],
        ["Switzerland","CH","2756"],
        ["Taiwan","TW","2158"],
        ["Tajikistan","TJ","2762"],
        ["Tanzania","TZ","2834"],
        ["Thailand","TH","2764"],
        ["Togo","TG","2768"],
        ["Tokelau","TK","2772"],
        ["Tonga","TO","2776"],
        ["Trinidad and Tobago","TT","2780"],
        ["Tunisia","TN","2788"],
        ["Turkey","TR","2792"],
        ["Turkmenistan","TM","2795"],
        ["Turks and Caicos Islands","TC","2796"],
        ["Tuvalu","TV","2798"],
        ["Uganda","UG","2800"],
        ["Ukraine","UA","2804"],
        ["United Arab Emirates","AE","2784"],
        ["United Kingdom","GB","2826"],
        ["United States","US","2840"],
        ["United States Minor Outlying Islands","UM","2581"],
        ["Uruguay","UY","2858"],
        ["Uzbekistan","UZ","2860"],
        ["Vanuatu","VU","2548"],
        ["Vatican","VA","2336"],
        ["Venezuela","VE","2862"],
        ["Viet Nam","VN","2704"],
        ["Virgin Islands (British)","VG","2092"],
        ["Virgin Islands (U.S.)","VI","2850"],
        ["Wallis and Futuna Islands","WF","2876"],
        ["Western Sahara","EH","2732"],
        ["Yemen","YE","2887"],
        ["Zambia","ZM","2894"],
        ["Zimbabwe","ZW","2716"]
      ]
    
      def self.find_name_by_country_code(country_code)
        country_code = country_code.upcase
        COUNTRIES.find { |name,code,id| country_code == code }.first rescue nil
      end

    end
  end  
end
